package lumis.service.wsrp.common;

import com.sun.portal.wsrp.producer.ProducerVersion;

/**
 * Enum that holds values from {@link ProducerVersion} to be shown in the
 * interface.
 * 
 * @version $Revision: 12565 $ $Date: 2011-02-15 16:20:59 -0200 (Tue, 15 Feb 2011) $
 * @since 5.5.0
 */
public enum WSRPVersionFromTo
{
	/**
	 * Equivalent of {@link ProducerVersion#BOTH}
	 * 
	 * @since 5.5.0
	 */
	Both("STR_VERSION_BOTH", ProducerVersion.BOTH.value()),

	/**
	 * Equivalent of {@link ProducerVersion#VERSION1}
	 * 
	 * @since 5.5.0
	 */
	Version1("STR_VERSION_1", ProducerVersion.VERSION1.value()),

	/**
	 * Equivalent of {@link ProducerVersion#VERSION2}
	 * 
	 * @since 5.5.0
	 */
	Version2("STR_VERSION_2", ProducerVersion.VERSION2.value())
	;

	private String value;

	private String localizableName;

	/**
	 * Constructor that receives a localizable string and a value as its
	 * parameters.
	 * 
	 * @param localizableName
	 *            A localizable string.
	 * @param value
	 *            A value that represents this constant.
	 * @since 5.5.0
	 */
	private WSRPVersionFromTo(String localizableName, String value)
	{
		this.localizableName = localizableName;
		this.value = value;
	}

	/**
	 * Returns this constant value.
	 * 
	 * @return The value of this constant.
	 * @since 5.5.0
	 */
	public String getValue()
	{
		return value;
	}

	/**
	 * Returns this constant localizable string.
	 * 
	 * @return A localizable string.
	 * @since 5.5.0
	 */
	public String getLocalizableName()
	{
		return localizableName;
	}

	/**
	 * Returns a {@link WSRPVersionFromTo} which contains the same value of
	 * <code>value</code>.
	 * If there isn't such constant, a null reference is returned.
	 * 
	 * @param value
	 *            A comparison value to get a {@link WSRPVersionFromTo} from.
	 * @return A {@link WSRPVersionFromTo} or a null reference if there isn't a
	 *         constant with the same value of <code>value</code>.
	 * @throws IllegalArgumentException
	 * @since 5.5.0
	 */
	public static WSRPVersionFromTo getFromValue(String value) throws IllegalArgumentException
	{
		if (value == null)
			throw new IllegalArgumentException("STR_NULL_VALUE_PASSED");

		WSRPVersionFromTo ret = null;
		for (WSRPVersionFromTo versionFromTo : values())
		{
			if (versionFromTo.getValue().equals(value))
			{
				ret = versionFromTo;
				break;
			}
		}

		return ret;
	}
}